#define  _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int integerReplacement(int n) {
        long long x = n;
        int ret = 0;
        while (x != 1)
        {
            if ((x & 1) == 0) //ĩβΪ0
                x >>= 1;
            else if (x == 3 || (x & 3) == 1) //ĩβΪ 01
                x--;
            else x++;       //ĩβΪ 11
            ret++;
        }
        return ret;
    }
};